/**
 * task manage page logic.
 */
var __taskId = null;
function loadTask(taskId) {
	$('#taskViewContainer').load('/loadTask?taskId='+taskId, function(){
		$('#taskViewContainer').trigger('create');
	});
}

function pageinit() {
	$('#lvTasks').find('.taskId').each(function(i, a) {
		var input = $(a).find("input").first();
		var taskId = input.val();
		$(a).off('click').on('click', function(event) {
			__taskId = taskId;
			$("#taskName").text("Task: " + __taskId);
			loadTask(__taskId);
			event.preventDefault();
		});
	});

	$('#addTask').off('click').on('click', function(event) {
		$.mobile.changePage("/addTask?a=newTask", {
			transition : "flip",
			role : "dialog"
		});
		event.preventDefault();
	});
}

$(document).on('pageinit', function() {
	pageinit();
});
